﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 

namespace MaxStudio.Concrete.Server.Service
{
     public class  MotorcadeService :ServiceHandle, IMotorcade
    {
        #region IMotorcade Members

     //    ConcreteDaoDataContext dataContext = new ConcreteDaoDataContext();

         public OperationResult<List<tb_Motorcade>> GetAllMotorcade()
        { 
            OperationResult<List<tb_Motorcade>> result = new OperationResult<List<tb_Motorcade>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_Motorcade> list = new List<tb_Motorcade>();
            try
            {
                list = dataContext.GetAllMotorcade();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

         public OperationResult<tb_Motorcade> GetMotorcadeById(int id)
        {
            OperationResult<tb_Motorcade> result = new OperationResult<tb_Motorcade>();
            ConcreteDaoDataContext dataContext = getDateContext();
            tb_Motorcade motorcade;
            try
            {
                motorcade = dataContext.GetMotorcadeById(id);
                if (motorcade == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = motorcade;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

         public OperationResult<tb_Motorcade> CreateMotorcade(tb_Motorcade entity)
        {
            OperationResult<tb_Motorcade> result = new OperationResult<tb_Motorcade>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.CreateMotorcade(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

         public OperationResult<tb_Motorcade> ModifyMotorcade(tb_Motorcade entity)
        {
            OperationResult<tb_Motorcade> result = new OperationResult<tb_Motorcade>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.ModifyMotorcade(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

         public OperationResult<tb_Motorcade> DeleteMotorcade(tb_Motorcade entity)
        {
            OperationResult<tb_Motorcade> result = new OperationResult<tb_Motorcade>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.DeleteMotorcade(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
